<template>
  <div class="resetPwd">
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="省份" prop="province">
        <el-select v-model="form.province" placeholder="请选择省份" style="width: 100%">
          <el-option
            v-for="item in form.provinces"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="城市" prop="city">
        <el-select v-model="form.city" placeholder="请选择城市" style="width: 100%">
          <el-option
            v-for="item in form.cities"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="详细地区">
        <el-input v-model="form.clock"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="reset">确认修改</el-button>
      </el-form-item>

    </el-form>
  </div>
</template>

<script>
    import {requestPost} from "../../../network/request";

    export default {
        props:['id'],
        name: "resetAddress",
      data(){
          return{
            id:'',
            form:{
              provinces: [ {
                value: '广东省',
                label: '广东省'
              },],
              cities:[
                {
                  value: '广州市',
                  label: '广州市'
                }, {
                  value: '深圳市',
                  label: '深圳市'
                }, {
                  value: '珠海市',
                  label: '珠海市'
                },
                {
                  value: '佛山市',
                  label: '佛山市'
                },
                {
                  value: '梅山市',
                  label: '梅山市'
                }
              ],
              city:'',
              province:'',
              clock:'',
              addressName: '',
            }
          }
      },
      mounted() {
          console.log(this.id)
          requestPost({
            url:'address/search',
            data:{
              addressId:this.id
            }
          }).then(res=>{
            this.form.addressName = res.data.address.addressName;
          })
      },
      methods:{
        reset(){
          this.form.addressName = this.form.province+this.form.city+this.form.clock;
          requestPost({
            url: 'address/update',
            data:{
              addressId :this.id,
              addressName: this.form.addressName,
            }
          }).then(res=>{
            alert("修改成功");
            this.$router.replace("/content/suggestion");
          })

        }
      }
    }
</script>

<style scoped>
  .resetPwd{
    text-align: center;
    margin: 0 auto;
    width: 50%;
    padding-top: 5%;
  }
</style>
